#!/bin/bash
# Empties out the solr index and re-imports all records
# i run this aprox twice a year
# can be run as libadmin except the stop/start of solr which needs to be root
#
MARCIMPORT=/usr/local/marcimport
SABRE=/usr/local/vufind-smu
# Disable JETTY_CONSOLE output -- it causes problems when run by cron:
export JETTY_CONSOLE=/dev/null
#
date
#
############################################
# Get files...
cd $MARCIMPORT
pwd
./full-getsussex.sh
sleep 10
#
# check that we have some files and data
#FILE="$MARCIMPORT/full/sussexincoming/grabbed.bibsg1.mrc"
#if [[ -s $FILE ]] ; then
#	echo "$FILE has data."
#else
#	echo "$FILE is empty. So Exit"
#	cd $SABRE
#	exit
#fi 
# ...
# Get Brighton data
cd $MARCIMPORT
./full-getbrighton.sh
echo full brighton import done
date
#
#################################################
# delete current index 
echo "Stop vufnd and take a backup of the solr index"
cd $SABRE
#this needs to be run as root to stop and start solr
#./full-emptysolr.sh
sleep 10

# solr needs to be running again (and empty) from here.

# ############################################ 
# Pre-process Sussex files
echo "Pre process Sussex MARC files"
$MARCIMPORT/full-preprocesssussex.sh
#
# ##############################################
# vufind import sussex files
$MARCIMPORT/full-importsussex.sh
#
#
#################################
# pre-process Brighton files
$MARCIMPORT/full-preprocessbrighton.sh
#
####################################
# vufind import brighton files
$MARCIMPORT/full-importbrighton.sh

################################################
# optimise and start it back up
cd $SABRE/util
echo "starting optimise..."
php optimize.php
echo "Finished optimise..."
date
cd $SABRE
echo "Full import finished"
date

